package com.smh.a08Test2;

import java.io.*;
import java.net.ServerSocket;
import java.net.Socket;

public class Server {
    public static void main(String[] args) throws IOException {

        ServerSocket ss = new ServerSocket(10005);

        Socket accept = ss.accept();
        InputStream is = accept.getInputStream();
        BufferedReader br = new BufferedReader(new InputStreamReader(is));

        StringBuilder sb = new StringBuilder();
        int b;
        //需要有一个结束标记,不然会死等
        while ((b = br.read()) != -1) {
            sb.append((char) b);
        }
        System.out.println(sb);

        //写回数据
        String s = "12313123";

        OutputStream os = accept.getOutputStream();
        os.write(s.getBytes());

        os.close();
        br.close();
        accept.close();
        ss.close();


//        Scanner scanner = new Scanner(System.in);
//        Socket socket = new Socket("127.0.0.1", 10007);
//
//        OutputStream os = socket.getOutputStream();
//
//        byte[] bytes = scanner.nextLine().getBytes();
//        os.write(bytes);
//
//        os.close();
//        socket.close();


    }
}
